﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Runtime.Serialization;
using System.Text;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using DocumentFormat.OpenXml.Packaging;


namespace vpGrid.Tests
{
    [DataContract]
    public class ProductViewModel
    {
        [DataMember(Name = "remoteId", Order = 1)]
        public string Id { get; set; }

        [DataMember(Name = "name", Order = 2)]
        public string Name { get; set; }

        [DataMember(Name = "producNumber", Order = 3)]
        public string ProducNumber { get; set; }

        [DataMember(Name = "salable", Order = 4)]
        public string AvailableToSell { get; set; }

        [DataMember(Name = "price", Order = 5)]
        public string Price { get; set; }

        [DataMember(Name = "style", Order = 6)]
        public string Style { get; set; }

        [DataMember(Name = "safetyStockLevel", Order = 7)]
        public string SafetyStockLevel { get; set; }

        [DataMember(Name = "color", Order = 8)]
        public string Color { get; set; }

        [DataMember(Name = "weight", Order = 9)]
        public string Weight { get; set; }

        [DataMember(Name = "weightUnit", Order = 10)]
        public string WeightUnit { get; set; }

        [DataMember(Name = "isUpdatable", Order = 11)]
        public bool IsUpdatable { get; set; }

        [DataMember(Name = "isDeletable", Order = 11)]
        public bool IsDeletable { get; set; }
    }

    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            string filePath = @"C:\Users\Henri d'Orgeval\Documents\Visual Studio 2013\Projects\vpGrid\vpGrid.Tests\AdventureWorks.Products.csv";
            string[] entries = System.IO.File.ReadAllLines(filePath, Encoding.UTF7);
            List<ProductViewModel> products = new List<ProductViewModel>();

            for (int i = 222; i < (222+100) - 1; i++)
            {
                string entry = entries[i];
                string[] separators = new string[] { ";" };
                string[] values = entry.Split(separators, StringSplitOptions.None);

                var price = values[9];
                price = price.Replace(",", ".");
                price = price.Replace(" ", "");
                
                var product = new ProductViewModel()
                {
                    Id = values[0],
                    Name = values[1],
                    ProducNumber = values[2],
                    Price = price,
                    Style = values[17].Trim(),
                    SafetyStockLevel = values[6],
                    Color = values[5],
                    Weight = values[13],
                    WeightUnit = values[12].Trim(),
                    IsDeletable = true,
                    IsUpdatable = true
                };

                product.AvailableToSell = "no";
                if (values[4] == "1")
                {
                    product.AvailableToSell = "yes";
                }
                if ((i % 7) == 0)
                {
                    product.AvailableToSell = "yes";
                }

                products.Add(product);
            }

            string jsonArray = products.ToJson();

        }

        [TestMethod]
        public void TestMethod2()
        {
            List<string> entries = new List<string>();
            for (int i = 1; i < 4000; i++)
            {

                string entry = string.Format(@"test{0} {1}", i, i % 7);

                entries.Add(entry);
            }

            string jsonArray = entries.ToArray().ToJson();

        }

        
    }
}
